//
// Created by vcq on 21/4/2.
//
#include <cstdlib>
#include "model/_user_manager.hpp"

static void GetUserManager(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    basic_string_view<char> id = req.get_query_value("id");
    basic_string_view<char> user_id = req.get_query_value("user_id");
    basic_string_view<char> manager_id = req.get_query_value("manager_id");
    basic_string_view<char> manager_type = req.get_query_value("manager_type");
    json item = MGetUserManager(id, user_id, manager_id, manager_type);
    res.set_status_and_content(status_type::ok, item.dump(), req_content_type::json);
}

static void AddUserManager(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    struct _user_manager _user_manager1{};
    _user_manager1.id = atoi(req.get_query_value("id").data());
    _user_manager1.user_id = atoi(req.get_query_value("id").data());
    _user_manager1.manager_id = atoi(req.get_query_value("id").data());
    _user_manager1.manager_type = atoi(req.get_query_value("id").data());
    _user_manager1.note = req.get_query_value("id");
    MAddUserManager(_user_manager1);
    res.set_status_and_content(status_type::ok);
}

static void DeleteUserManager(request &req, response &res) {
    if (!check_login(req, res)) {
        return;
    }
    MDeleteUserManager(req.get_query_value("id"));
    res.set_status_and_content(status_type::ok);
}